Given the class below, class three_d{ int x, y, z; three_(int i, int j, int k) { x = i; y = j; z = k; } three_() {x=0; y=0;...

      

Given the class below,
class three_d{
int x, y, z;
three_(int i, int j, int k)
{
x = i; y = j; z = k; }
three_() {x=0; y=0; z=0; }
void get(in int &j, int &k){
i = x; j = y; k = z;}
};
Rewrite it so that it uses reference parameters to the operator functions.

  

Answers


Davis
#include
using namespaced;
class three_d {
int x, y, z;
public:
three_d(int i, int j, int k)
{
x=i; y=j; z=k;}
three_d() {x=0; y=0; z=0;}
void get(int &i, int &j, int{
i=x; j=y; k=z;
}
three_d operator+(three_d &ob2);
three_d operator-(three_d &ob2);
friend three_d operator++ (three_d &ob);
friend three-d operator(three_d &ob2);
};
three_d three_d::operator+(three_d &ob2) {
three_d temp;
temp.x = x + ob2.x;
temp.y = y + ob2.y;
temp.z = z + ob2.z;
return temp;}
three_d three_d::operator-(three_d &ob2) {
three_d temp;
temp.x = x - ob2.x;
temp.y = y - ob2.y;
temp.z = z - ob2.z;
return temp;
}
three_d operr++(three_d &ob)
{
ob.x++;
ob.y++;
ob.z++;
return ob;
}
three_d operator--(three_d &ob) {
ob.x--;
ob.y--;
ob.z--;
return ob;
}
int main()
{
th(10, 10, 10), o2(2, 3, 4) o3;
int x, y, z;
o3 = o1 + o2;
o3.get(x, y, z);
cout << "x: "<cout << " z: " < o3= o1 - o2;
o3.ge(x, y, z);
cout << "x: "<cout << " z: " <++o1;
o1.get(x, y, z);
cout << x: "<< x<<" y: "<cout << " z: " <--;
o1.get(x, y, z);
cout << "x: "<cout << " z: " <return 0;

Githiari answered the question on June 8, 2018 at 19:18


Next: Given the following class declaration; class dynarray { int *p; int size; public: dynarray(int s); int &put(int i); int get(int i); //create operator=( function }; fill in all the details that will create a...
Previous: Overload the >> and << shift operators relative to the coord class so that the following types of operations are allowed: ob << integer ob >> integer make sure your operators shift the x and y values by the amount specified.

View More Computer Science Questions and Answers | Return to Questions Index


Exams With Marking Schemes

Related Questions